import InteractiveBase from "../../../LevelCommon/InteractiveBase";
import EnumData from "../../../../Enum/EnumData";
import { utils } from "../../../../utils/CommonUtil";
import Sound from "../../../../constant/SoundNameConstant";
enum MoveStatus {
    Oringin,
    Target,
}
export default class MoveObj extends InteractiveBase {
    /** 初始位置 local*/
    private oringinPos: Laya.Vector3;
    /** 目标位置 local*/
    public targetPos: Laya.Vector3;
    /** 移动时间*/
    public tweenTime: number = 500;

    /** 当前移动状态*/
    private curMoveStatus: MoveStatus = MoveStatus.Oringin;

    /** 要播放的音频资源名字*/
    public VoiceName: string;

    //是否转换unity坐标到laya
    public isConvertUnityPosition:boolean = true;

    private mowner: Laya.Sprite3D;

    onStart() {
        this.mowner = this.owner as Laya.Sprite3D;
        this.oringinPos = this.mowner.transform.localPosition.clone();
    }
    /** 移动向目标点*/
    public MoveTarget(): void {
        this.curMoveStatus = MoveStatus.Target;
        console.log("this.isConvertUnityPosition",this.isConvertUnityPosition)
        utils.CommonUtils.DOPositionTween(
            this.mowner.transform,
            this.mowner.transform.localPosition,
            this.targetPos, this.tweenTime,
            Laya.Handler.create(this, function () {
                console.log("移动到了目标位置了",this.targetPos);

            }), true,false,this.isConvertUnityPosition)
    }

    /** 移动回初始位置*/
    public MoveOrigin(): void {
        this.curMoveStatus = MoveStatus.Oringin;
        utils.CommonUtils.DOPositionTween(
            this.mowner.transform,
            this.mowner.transform.localPosition,
            this.oringinPos, this.tweenTime,
            Laya.Handler.create(this, function () {
                console.log("回到了初始位置了");
                this.mowner.transform.localPosition  = this.oringinPos;
            }), true,false,false)
    }

    protected InteractiveLogic(): boolean {
        if (this.curMoveStatus == MoveStatus.Oringin) {
            this.MoveTarget();
        }
        else {
            this.MoveOrigin();
        }
        if (!utils.CommonUtils.isEmpty(this.VoiceName)) {
            window.gameFacade.SoundMng.playSound(this.VoiceName);

        }
        return true;
    }
    /** public 交互逻辑*/
    public Interactive(): void {
        this.InteractiveLogic();
    }
}